home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Miscellaneous
/
ival
/
dlog.c
next >
Wrap
Text File
|
1987-05-25
|
2KB
|
89 lines
/*
* dlog.c - misc dialog item handling routines.
*
*/
#include <memory.h>
#include <quickdraw.h>
#include <window.h>
#include <event.h>
#include <textedit.h>
#include <dialog.h>
#include <control.h>
#include <toolutil.h>
#include <resource.h>
/*
* radioswitch() - turn one radio button off & another one on,
* returning the item ID of the new "on" button.
*/
int
radioswitch(dlg, oncontrl, offcontrl)
DialogPtr dlg;
int oncontrl, offcontrl; /* items to turn on and off, respectively */
{
int itemtype;
ControlHandle item;
Rect itembox;
GetDItem(dlg, offcontrl, &itemtype, &item, &itembox);
SetCtlVal(item, 0);
GetDItem(dlg, oncontrl, &itemtype, &item, &itembox);
SetCtlVal(item, 1);
return(oncontrl);
}
/*
* radioset() - set one of a set of radio items, clearing the others.
*/
radioset(dlg, onitem, firstitem, lastitem)
DialogPtr dlg;
short onitem; /* item # of the item to turn on */
/*... == 0 means "turn everything off" */
short firstitem; /* item # of the first item of the set */
short lastitem; /* item # of the last item of the set */
{
short itemnum; /* item # of the current item */
short itemtype;
ControlHandle item;
Rect itembox;
for (itemnum = firstitem; itemnum <= lastitem; ++itemnum) {
GetDItem(dlg, itemnum, &itemtype, &item, &itembox);
SetCtlVal(item, itemnum == onitem ? 1 : 0);
}
}
/*
* justdigs() - restrict the contents of an EditText item to just the given
* number of digits. I.E., throw out non-digit characters & characters
* beyond the end of the field.
* The field must be less than 100 characters wide.
*/
justdigs(dlg, field, width)
DialogPtr dlg;
int field; /* # of the dialog item to modify */
int width; /* max # of digits in the field */
{
int itemtype;
ControlHandle item;
Rect itembox;
static char buf[100];
char *src, *dst; /* pointers for removing non-digits */
GetDItem(dlg, field, &itemtype, &item, &itembox);
GetIText(item, buf);
ptoc(buf);
dst = &buf[0];
for (src = &buf[0]; (*dst = *src); ++src) {
if (*dst >= 0 && *dst <= '9') ++dst;
}
buf[width] = '\0';
ctop(buf);
SetIText(item, buf);
}